package com.base.obj;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

/**
 * create by yongli on 2021-06-04 16:41
 */

public class TimeStrampTest {

    private static final Logger logger = LoggerFactory.getLogger(TimeStrampTest.class);

    public static void main(String[] args) {

        for (int i = 0; i < 100; i++) {
            timeStrampTest();
        }
    }


    public static void timeStrampTest() {
        Instant instant = Instant.now();
        // 测试服这个并发安全性问题
        DateTimeFormatter.ISO_LOCAL_DATE.format(instant);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-hh-mm-sss", Locale.US);
        String str = formatter.format(instant);
        logger.info(str);

    }

    public static void instanceTest() {
        LocalDateTime time = LocalDateTime.now();
        // 都使用了工厂方法，而不是构造函数，可能从名字上说，好听一点？
        Instant instant = Instant.now();
        System.out.println(instant);
        Date date = new Date();
        System.out.println(date);
        System.out.println(time);
        System.out.println(time.getDayOfMonth());
        int month = time.getMonthValue();
        System.out.println("month value:" + month);
        System.out.println(time.getMonth());
        System.out.println(time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }
}
